﻿#region references
using System;
using System.Web.UI;
using System.Collections.Generic;
using System.Web.Security;
using System.Web.UI.WebControls;

/* Project dependencies */
using IcaGames.Logging;
using IcaGames.Database;
using IcaGames.Objects;
using IcaGames.Database.ObjectManagement;
#endregion

    public partial class Search : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    /* Get the search results for the search query */
                    string searchQuery = Request.QueryString["q"].ToString().Replace('_', ' ');

                    List<Game> searchResults = DatabaseStore.GetSearchResults(searchQuery);
                    ((TextBox)Page.Master.FindControl("txtSearch")).Text = searchQuery;

                    ucSearchResults._gameSearchResults = searchResults.Count.ToString();
                    ucSearchResults._gvGamesDataSource = searchResults;

                    List<Publisher> publishers = PublisherManagement.GetPublishers(searchQuery);
                    ucSearchResults._publisherSearchResults = publishers.Count.ToString();
                    ucSearchResults._gvPublisherDataSource = publishers;
                }
                catch (Exception ex)
                {
                    Log.CreateLog("Exception while getting QueryString from frontpage", "SEARCH");
                    Log.CreateLog(ex.Message, "SEARCH");
                }
            }
        }
    }
